/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simplemetrosystem.model.Command.EditCommand;

import javax.swing.JOptionPane;
import simplemetrosystem.control.ElementManager;
import simplemetrosystem.model.Command.Command;
import simplemetrosystem.model.Element.MetroStation;
import simplemetrosystem.model.charlanguage.NameMap;

/**
 *
 * @author Eric Qian
 */
public class AddStationCommand implements Command {

    /**
     * 
     * @param name 
     * @param logX
     * @param logY 
     */
    public AddStationCommand(String name, int logX, int logY) {
        this.name = name;
        this.logX = logX;
        this.logY = logY;
        success = false;
    }

    public void execute() {
        ElementManager manager = ElementManager.getInstance();
        if (manager.addStation(name, name, logX, logY, 0, 0)) {
            station = manager.findStation(name);
            success = true;
        } else {
            JOptionPane.showMessageDialog(null, nameMap.getName("Fail to add station"),
                    nameMap.getName("WARNING"), JOptionPane.WARNING_MESSAGE);
        }
    }

    public void undo() {
        if(success){
            ElementManager.getInstance().removeStation(station);
        }
    }
    private boolean success;
    private NameMap nameMap;
    private MetroStation station;
    private String name;
    private int logX;
    private int logY;
}
